<?php if(!isset($_SESSION)){
  session_start(); $message="";
}
require_once('../../Connections/microassur.php');
require_once('../../utils/fonctions.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_rs_mod = "-1";
if (isset($_GET['Identifiant_refext'])) {
  $colname_rs_mod = $_GET['Identifiant_justificatif'];
}
if(isset($_GET['supp']))
{
mysql_query("START TRANSACTION");
$rq=mysql_query("delete  from justificatif where Identifiant_justificatif='".$colname_rs_mod."'");
if($rq)
{
mysql_query("commit"); header("location:index.php?supp=succes");
}
else mysql_query("rollback"); 
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

$bool=verifLibelle("Valeur_justificatif");
if (isset($_POST["MM_update"]) && $_POST["MM_update"] == "form2" && $bool) {
  $updateSQL = sprintf("UPDATE justificatif SET Type_justificatif=%s, Valeur_justificatif=%s WHERE Identifiant_justificatif=%s",
                       GetSQLValueString($_POST['Type_justificatif'], "text"),
                       GetSQLValueString($_POST['Valeur_justificatif'], "text"),
                       GetSQLValueString($_POST['Identifiant_justificatif'], "int"));

  mysql_select_db($database_microassur, $microassur);
  mysql_query("START TRANSACTION");
  $Result1 = mysql_query($updateSQL, $microassur) or die(mysql_error());
  if(!$Result1){  mysql_query("rollback");
	  header("location:index.php?mod=echec&Identifiant_personne=".$_GET['Identifiant_personne']);
   }
   else 	{ mysql_query("commit");  //header("location:index.php?mod=success&Identifiant_personne=".$_GET['Identifiant_personne']);
   }

}
 if (isset($_POST["MM_update"]) && $_POST["MM_update"] == "form1" && !$bool) {
if(empty($_POST['Valeur_refext']))$message=colorer("Vous devez saisir la valeur de la référence externe","true");
elseif(!verifLibelle('Valeur_refext'))$message=colorer("La valeur de la référence externe saisie comporte des caractères spéciaux interdits ","false");
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1") && $bool) {
  $insertSQL = sprintf("INSERT INTO justificatif (Identifiant_justificatif, Type_justificatif, Valeur_justificatif, Identifiant_contrat, Identifiant_personne, Identifiant_evenement, Identifiant_sinistre) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['Identifiant_justificatif'], "int"),
                       GetSQLValueString($_POST['Type_justificatif'], "text"),
                       GetSQLValueString($_POST['Valeur_justificatif'], "text"),
                       GetSQLValueString($_SESSION['idcontrat'], "int"),
                       GetSQLValueString($_GET['Identifiant_personne'], "int"),
                       GetSQLValueString($_POST['Identifiant_evenement'], "int"),
                       GetSQLValueString($_POST['Identifiant_sinistre'], "int"));

  mysql_select_db($database_microassur, $microassur);
   mysql_query("START TRANSACTION");
  $Result1 = mysql_query($insertSQL, $microassur) or die(mysql_error());
  if(!$Result1){  mysql_query("rollback");
	  header("location:index.php?ajout=echec&Identifiant_personne=".$_GET['Identifiant_personne']);
   }
   else  { mysql_query("commit");
   //header("location:index.php?ajout=success&Identifiant_personne=".$_GET['Identifiant_personne']);
   }
}
 if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1") && !$bool) {
if(empty($_POST['Valeur_refext']))$message=colorer("Vous devez saisir la valeur du justificatif","true");
elseif(!verifLibelle('Valeur_refext'))$message=colorer("La valeur du justificatif saisie comporte des caractères spéciaux interdits ","false");
}
$colname_rs_mod = "-1";
if (isset($_GET['Identifiant_justificatif'])) {
  $colname_rs_mod = $_GET['Identifiant_justificatif'];
}
mysql_select_db($database_microassur, $microassur);
$query_rs_mod = sprintf("SELECT * FROM justificatif WHERE Identifiant_justificatif = %s", GetSQLValueString($colname_rs_mod, "int"));
$rs_mod = mysql_query($query_rs_mod, $microassur) or die(mysql_error());
$row_rs_mod = mysql_fetch_assoc($rs_mod);
$totalRows_rs_mod = mysql_num_rows($rs_mod);

$colname_rs1 = "-1";
if (isset($_GET['Identifiant_justificatif'])) {
  $colname_rs1 = $_GET['Identifiant_justificatif'];
}
mysql_select_db($database_microassur, $microassur);
$query_rs1 = sprintf("SELECT * FROM justificatif WHERE Identifiant_justificatif = %s", GetSQLValueString($colname_rs1, "int"));
$rs1 = mysql_query($query_rs1, $microassur) or die(mysql_error());
$row_rs1 = mysql_fetch_assoc($rs1);
$totalRows_rs1 = mysql_num_rows($rs1);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Justificatif</title>
			<link rel="stylesheet" type="text/css" href="../../css/main.css" />
            <link rel="stylesheet" type="text/css" href="list.css" />
			<!--[if IE 7]>
            	<link rel="stylesheet" type="text/css" href="../../css/ie7.css" />
            	<link rel="stylesheet" type="text/css" href="form_ie7.css" />
            <![endif]--></head>

<body>
<div id="sf_menu1">
<h3>Production </h3>
<?php
	

	if(isset($message) && !empty($message)){
		echo $message;
	}
	$nommodule="Justificatif";
	//$nommodule2="Liste des adresse";
	$nom_module_saisie="Ecran saisie";
?>
</div>
<div class="cleared"></div>

<div class="corps1">
<div class="cleared"></div>

<?php if(!isset($_GET['Identifiant_justificatif'])) {?>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
 <div class="imgleft"></div>
	<div class="imgmiddle">
    <div class="btn">
    	<span class="btnleft"></span>
        <span class="btnmiddle">
        	<h5><?php echo $nommodule; ?></h5>
        </span><span class="btnright"></span>
    </div>
  	<div class="btn1">
    	<span class="btnleft"></span>
        <span class="btnmiddle">
        	<h5><?php echo $nom_module_saisie; ?></h5>
        </span>
        <span class="btnright"></span>
    </div>
	<div class="formulaire">
  <table class="tabform">
    <tr >
      <td  class="td1">TYPE</td>
      <td>
      <select name="Type_justificatif" id="Type_justificatif"  >
      <?php $requete=mysql_query("select elementdico.* from dictionnaire,elementdico where dictionnaire.Code_table='M0010' and dictionnaire.Identifiant_table=elementdico.Identifiant_table");
	 
	  while($reponse=mysql_fetch_array($requete)) {?>
        <option <?php  if(isset($_SESSION['Type_justificatif'])) echo remind_select1('Type_justificatif', $reponse["Code_element"]) ; else echo remind_select('Type_justificatif',$reponse["Code_element"]);?> value="<?php echo $reponse["Code_element"];?>"><?php echo $reponse["Nom_element"];?></option>
        <?php }?>
        </select>        
      
      </td>
    </tr>
    <tr >
      <td class="td1">VALEUR</td>
      <td><input name="Valeur_justificatif" type="text" value="" size="32" maxlength="30" /></td>
    </tr>
  </table>
  
  </div>
    
 </div>

<div class="imgright"></div>				
<div class="cleared"></div>
    
    
    <div class="bt1"> <a href="index.php?Identifiant_personne=<?php echo $_GET['Identifiant_personne']?>"><span class="btleft"></span>
        <span class="btmiddle">Annuler</span>
        <span class="btright"></span>
    </a></div>
    
      <div class="bt">
	<span class="btleft"></span><input type="submit" value="Valider" class="resizeall btmiddle"/>
    <span class="btright"></span></div>
    
	 
  
  
    
    
  <input type="hidden" name="Identifiant_justificatif" value="" />
  <input type="hidden" name="Identifiant_contrat" value="" />
  <input type="hidden" name="Identifiant_personne" value="" />
  <input type="hidden" name="Identifiant_evenement" value="" />
  <input type="hidden" name="Identifiant_sinistre" value="" />
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<?php }
else
{?>


<form action="<?php echo $editFormAction; ?>" method="post" name="form2" id="form2">
<div class="imgleft"></div>
	<div class="imgmiddle">
    <div class="btn">
    	<span class="btnleft"></span>
        <span class="btnmiddle">
        	<h5><?php echo $nommodule; ?></h5>
        </span><span class="btnright"></span>
    </div>
  	<div class="btn1">
    	<span class="btnleft"></span>
        <span class="btnmiddle">
        	<h5><?php echo $nom_module_saisie; ?></h5>
        </span>
        <span class="btnright"></span>
    </div>
	<div class="formulaire">
  <table class="tabform">
    <tr>
      <td class="td1">TYPE</td>
      <td> <select name="Type_justificatif" id="Type_justificatif"  >
      <?php $requete=mysql_query("select elementdico.* from dictionnaire,elementdico where dictionnaire.Code_table='M0010' and dictionnaire.Identifiant_table=elementdico.Identifiant_table");
	 
	  while($reponse=mysql_fetch_array($requete)) {?>
        <option <?php  if(isset($_SESSION['Type_justificatif'])) echo remind_select1('Type_justificatif', $reponse["Code_element"]) ; else echo remind_select('Type_justificatif',$reponse["Code_element"]);?> value="<?php echo $reponse["Code_element"];?>"><?php echo $reponse["Nom_element"];?></option>
        <?php }?>
        </select>
      </td>
    </tr>
    <tr >
      <td class="td1">VALEUR</td>
      <td><input name="Valeur_justificatif" type="text" value="<?php echo htmlentities($row_rs_mod['Valeur_justificatif'], ENT_COMPAT, 'utf-8'); ?>" size="32" maxlength="30" /></td>
    </tr></table>
    
      
  
  </div>
    
 </div>

<div class="imgright"></div>				


    <div class="bt1"> <a href="index.php?Identifiant_personne=<?php echo $_GET['Identifiant_personne']?>"><span class="btleft"></span>
        <span class="btmiddle">Annuler</span>
        <span class="btright"></span>
    </a></div>
    
      <div class="bt">
	<span class="btleft"></span><input type="submit" value="Valider" class="resizeall btmiddle"/>
    <span class="btright"></span></div>
    
    <div class="cleared"></div>
	 
  
  <input type="hidden" name="Identifiant_justificatif" value="<?php echo $row_rs_mod['Identifiant_justificatif']; ?>" />
  <input type="hidden" name="Identifiant_contrat" value="<?php echo htmlentities($row_rs_mod['Identifiant_contrat'], ENT_COMPAT, 'utf-8'); ?>" />
  <input type="hidden" name="Identifiant_personne" value="<?php echo htmlentities($row_rs_mod['Identifiant_personne'], ENT_COMPAT, 'utf-8'); ?>" />
  <input type="hidden" name="Identifiant_evenement" value="<?php echo htmlentities($row_rs_mod['Identifiant_evenement'], ENT_COMPAT, 'utf-8'); ?>" />
  <input type="hidden" name="Identifiant_sinistre" value="<?php echo htmlentities($row_rs_mod['Identifiant_sinistre'], ENT_COMPAT, 'utf-8'); ?>" />
  <input type="hidden" name="MM_update" value="form2" />
  <input type="hidden" name="Identifiant_justificatif" value="<?php echo $row_rs_mod['Identifiant_justificatif']; ?>" />
</form>
<?php }?>
</div>
</body>
</html>
<?php
mysql_free_result($rs1);

mysql_free_result($rs_mod);

?>
